#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

int n,fi[4],en[4],ans;
char s[MAXN];

int main (){
	scanf("%s",s+1);n = strlen(s+1);
	for(int i = 1;i <= n;i++){
		if(!fi[s[i]-'a'])fi[s[i]-'a'] = i;
		en[s[i]-'a'] = i;
	}
	for(int i = 0;i < 3;i++)
		for(int j = 0;j < 3;j++)
			if(i != j && en[i] && fi[j]) ans = max(ans,en[i] - fi[j]);
	printf("%d\n",ans);
	return 0;
}
